package com.skivingcloud.develop.service.impl;

import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.skivingcloud.develop.entity.SysFormDesignerColumn;
import com.skivingcloud.develop.mapper.SysFormDesignerColumnMapper;
import com.skivingcloud.develop.service.SysFormDesignerColumnService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.skivingcloud.common.utils.PageParameter;

/**
 * 组件数据库字段描述表 服务层实现。
 *
 * @author skivingcloud
 * @since 2025-01-16
 */
@Service
public class SysFormDesignerColumnServiceImpl extends ServiceImpl<SysFormDesignerColumnMapper, SysFormDesignerColumn> implements SysFormDesignerColumnService {

    /**
     * 分页查询组件数据库字段描述表
     *
     * @param parameter 查询参数
     * @return 分页查询结果
     */
    @Override
    public Page<SysFormDesignerColumn> queryByPage(PageParameter<SysFormDesignerColumn> parameter){
        Page<SysFormDesignerColumn> page = new Page<>(parameter.getPage(), parameter.getPageSize());
        QueryWrapper queryWrapper = QueryWrapper.create();
        if (parameter.getParam() != null) {
            //查询条件
            if (StringUtils.isNoneBlank(parameter.getParam().getId())) {
                queryWrapper.and(SysFormDesignerColumn::getId).like(parameter.getParam().getId());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getFormId())) {
                queryWrapper.and(SysFormDesignerColumn::getFormId).like(parameter.getParam().getFormId());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getWidgetName())) {
                queryWrapper.and(SysFormDesignerColumn::getWidgetName).like(parameter.getParam().getWidgetName());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getColumnName())) {
                queryWrapper.and(SysFormDesignerColumn::getColumnName).like(parameter.getParam().getColumnName());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getColumnType())) {
                queryWrapper.and(SysFormDesignerColumn::getColumnType).like(parameter.getParam().getColumnType());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getColumnDes())) {
                queryWrapper.and(SysFormDesignerColumn::getColumnDes).like(parameter.getParam().getColumnDes());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getSubFormWidget())) {
                queryWrapper.and(SysFormDesignerColumn::getSubFormWidget).like(parameter.getParam().getSubFormWidget());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getSubFormName())) {
                queryWrapper.and(SysFormDesignerColumn::getSubFormName).like(parameter.getParam().getSubFormName());
            }
        }
        return this.page(page, queryWrapper);
    }
}
